export function deepMerge(target, ...sources) {
    if (!sources.length) return target;
    const source = sources.shift();

    if (isObject(target) && isObject(source)) {
        for (const key in source) {
            if (isObject(source[key])) {
                if (!target[key]) Object.assign(target, {[key]: {}});
                deepMerge(target[key], source[key]);
            } else {
                Object.assign(target, {[key]: source[key]});
            }
        }
    }

    return deepMerge(target, ...sources);
}

export function loadScriptTag(scriptJsId,src){
    let script = document.getElementById(scriptJsId);
    return new Promise((resolve, reject) => {
        if (script) {
            resolve()
            return
        }
        script = document.createElement("script");
        script.id = scriptJsId;
        script.type = "text/javascript";

        script.src = src;
        script.async = true;
        script.onload = resolve
        script.onerror = (event) => {
            script.remove()
            reject("加载失败office JS 失败请稍后再试！")
        }
        document.body.append(script)
    })
}
function isObject(item) {
    return (item && typeof item === 'object' && !Array.isArray(item));
}
